﻿import QtQuick 2.0
import QtQuick.Controls 2.0
import "./utils" as Utils

Rectangle{
    color: "#1F2A37"
    Grid{
        anchors.left: parent.left
        anchors.leftMargin: 200
        y: 156
        columns: 4
        spacing: 80
        Repeater{
            id: buttonRepeater
        //             BJ_PROPERTY(bool, key_screen_switch_enabled);      // 屏幕切换
        // BJ_PROPERTY(bool, key_data_load_query_enabled);    // 装载数据查询
        // BJ_PROPERTY(bool, key_decrement_bucket_enabled);   // 减一斗
        // BJ_PROPERTY(bool,
        //             key_lattice_limit_release_enabled);   // 光栅门限动解除
        // BJ_PROPERTY(bool,
        //             key_sensor_limit_release_enabled);   // 车身传感器限动解除
        // BJ_PROPERTY(bool, key_door_lock_override_enabled);   // 门锁越权
        // BJ_PROPERTY(bool, key_f1_enabled);
            model: [
                {"imgSourceDef": "qrc:/scraper/imgs/info_page_1.png", "btnByte": can_manager.key_screen_switch_enabled , "imgSource": "qrc:/scraper/imgs/info_page_1.png"},
                {"imgSourceDef": "qrc:/scraper/imgs/info_page_8.png", "btnByte": can_manager.key_ok_enabled , "imgSource": "qrc:/scraper/imgs/info_page_8.png"},
                {"imgSourceDef": "qrc:/scraper/imgs/info_page_2.png", "btnByte": can_manager.key_data_load_query_enabled , "imgSource": "qrc:/scraper/imgs/info_page_2.png"},
                {"imgSourceDef": "qrc:/scraper/imgs/info_page_3.png", "btnByte": can_manager.key_decrement_bucket_enabled , "imgSource": "qrc:/scraper/imgs/info_page_3.png"},
                {"imgSourceDef": "qrc:/scraper/imgs/info_page_4.png", "btnByte": can_manager.key_lattice_limit_release_enabled , "imgSource": "qrc:/scraper/imgs/info_page_4_.png"},
                {"imgSourceDef": "qrc:/scraper/imgs/info_page_5.png", "btnByte": can_manager.key_sensor_limit_release_enabled , "imgSource": "qrc:/scraper/imgs/info_page_5_.png"},
                {"imgSourceDef": "qrc:/scraper/imgs/info_page_6.png", "btnByte": can_manager.key_door_lock_override_enabled , "imgSource": "qrc:/scraper/imgs/info_page_6.png"},
                {"imgSourceDef": "qrc:/scraper/imgs/info_page_7.png", "btnByte": can_manager.key_f1_enabled , "imgSource": "qrc:/scraper/imgs/info_page_7.png"}, 
            ]
            delegate: Utils.MyLightBtnBeta{
                imageDefultSource: modelData.imgSourceDef
                imageLightSource: modelData.imgSource
                btnByte:modelData.btnByte
            }
        }
    }
    Timer {
        interval: 100 // 30Hz = 1000ms / 30 = 33.33ms
        running: true
        repeat: true
        onTriggered: {
            var pressStates = [];
            for (var i = 0; i < buttonRepeater.count; i++) {
                pressStates.push(buttonRepeater.itemAt(i).pressState ? 1 : 0);
            }
            sendPressStatesToCpp(pressStates);  // Send to C++
            
            // console.log("pressStates: "+pressStates)
            
        }
    }
    // Declare the function to send press states to C++
    function sendPressStatesToCpp(states) {
        // This function should be implemented in C++ as a slot to receive the data
        can_manager.sendKeyData(states);
    }
}